/**
 *
 */
package com.jinglu.cloud.security.access;

import com.jinglu.cloud.common.model.entity.Result;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 描述:  403 无权限访问处理.<br>
 *
 * @author lvzhenzhao
 * @date 2021年03月11日
 */
public class MyAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        response.setContentType("application/json;charset=utf-8");
        Result<String> result = Result.error(403, "无权限访问.");
        response.getOutputStream().write(result.toString().getBytes("UTF-8"));
        response.flushBuffer();
    }
}
